<template>
	<view class="wrap" :class="{
		'n-padd':tabCurrentIndex==2
	}">
	
		<image class="img" mode="widthFix" :src="imageUrl" :style="{ height: imgHeight + 'px' }" @load="onImgLoad" />
		<view class="navbar" :class="{
		'n-nother':tabCurrentIndex==2
	}">
	
			<!-- <view 
				v-for="(item, index) in navList" :key="index" 
				class="nav-item" 
				:class="{current: tabCurrentIndex === item.state}"
				@click="tabClick(item.state)"
			>
				{{item.text}}
			</view> -->
		</view>
		<view class="list-wrap" v-show="tabCurrentIndex==1">
			<view class="list-item" @click="nextpage(item)" v-for="(item,index) in dataList" :key="index">
				<view class="left">
					{{item.title}}
				</view>
				<view class="right">
					￥{{item.price}}   <text style="font-size:20rpx;position:relative;top:4rpx;"></text>
				</view>
			</view>
			
		</view>
		
		
		<view class="content-data" v-show="tabCurrentIndex==2">
			<view  class="data-wrap" v-for="(item,index) in datatree" :key="index" :class="{
				signcom:item.sign=='completed'
			}">
				<view class="left">
					
					<view class="info" style="padding-left:34rpx;">
						<view class="top">{{item.name}}</view>
						<view class="time" style="color:#e95758">
							{{item.subtitle}}
						</view>
					</view>
				</view>
				<view class="right">
					<view>{{item.amount}}</view>
					<view style="color:#b30b0b">{{item.remark}}</view>
				</view>
			</view>
			<uni-load-more  :status="more">
			</uni-load-more>
		</view>
		
	</view>
</template>


<script>
	import { mapState,mapMutations } from 'vuex'
	export default {
		data() {
			return {
				datatree:[],
				nowpage:1,
				tabCurrentIndex:1,
				dataList:[],
				navList: [{
							state: 1,
							text: '礼包预定',
							loadingType: 'more',
							orderList: []
						},
						{
							state: 2,
							text: '我的订单',
							loadingType: 'more',
							orderList: []
						}
						
					],
					more:'loading',
					imageUrl: 'https://fyimg.huayuyangchu.cn/statics/stock_list_bg.jpg',
					imgHeight: 0,
				
			}
		},
		
		onLoad() {
			// setgupiaotuijian(state,val){
			// 	state.gutiaotuijian=val
			// },
			
			
			//this.tabClick(1)
            this.geData()  
		},
		onNavigationBarButtonTap:function(e){
			
			uni.navigateTo({
				url: '/pages/wodeyuding/index?backstep=1'
			});
		               
		 },
		
		methods: {
			onImgLoad(e) {
			      // 当图片加载完成后，获取图片的原始宽度和高度，并根据宽度计算出高度
			      const { width, height } = e.mp.detail;
			      this.imgHeight = (height / width) * 100; // 高度 = 原始高度 / 原始宽度 * 100
			    },
			tabClick(index){
				
				this.datatree=[]
				this.nowpage=1
				this.tabCurrentIndex = index;
				this.more='loading'
				if(index==1){
					this.geData() 
				}else{
					this.getdingdan() 
				}
				
				
			},
			nextpage(item){
				uni.navigateTo({
				    url: `/pages/gupiaotuijiandetail/index?id=${item.id}`
				});
			},
			chooseImg(type){
				
				let that=this
				
				uni.chooseImage({
					count:1,
					sizeType:'compressed',
					success: (res) => {
						const imgsFile=res.tempFilePaths
						uni.showLoading({
						    title: '正在上传'
						});
						const uper=uni.uploadFile({
							url: that.upUrl+'/api/user/upimg_stock_sign',
							filePath:imgsFile[0],
							name:'img',
							header:{  
								"Authorization": uni.getStorageSync("auth_token")
							},
							success:function(res){
								
								
								let data=JSON.parse(res.data)
								if(data.Code=='10200'){
									
									uni.showToast({
										title: "上传成功",
										icon: "none",
										duration:4000,
									});
									uni.hideLoading();
									that[type]=data.Data
									
									
									
								}
							}
						})
						//上传进度更新的方法
						// uper.onProgressUpdate((e)=>{
						// 	if(e.progress==100){
								
								
						// 	}else{
								
						// 	}
							
						// })
					}
				})
			
			},
			onReachBottom() {
				if(this.more=='nomore'){
					return
				}
				this.getdingdan()	
			},
			geData(){
				let that=this
				that.apipost('/api/home/stock_recommend').then(res => {
					if(res.Code==10200){
						that.dataList=res.Data
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			getdingdan(){
				
				let that=this
				that.apipost('/api/home/my_order',{
					page:that.nowpage
					
				},true).then(res => {
					if(res.Code==10200){
						let data=res.Data
						that.datatree=that.datatree.concat(data)
						++that.nowpage
						uni.stopPullDownRefresh()
						
						if(data.length<15){
							
							that.more='nomore'
						}
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
			}
		}
	}
</script>

<style lang="scss">
	
	.list-item .left{
		font-size:32rpx;
		
	}
	.n-nother{
		
		
		position:relative!important;
		top:0!important;
	}
	.n-padd{
		background:none!important;
		padding:0!important;
		position:relative!important;
		top:0!important;
	}
	.list-item .right{
		font-size:32rpx;
		background:#f1511f;
		color:#fff;
		height:60rpx;
		border-radius:11rpx;
		width:140rpx;
		display:flex;
		align-items: center;
		justify-content: center;
	}
	.list-item{
		display:flex;
		justify-content: space-between;
		align-items: center;
		padding:0 30rpx 0 120rpx;
		background:url(/static/gupiaotuijianbgitem.png) no-repeat  40rpx center #fff;
		height:124rpx;
		background-size:54rpx auto;
		margin-bottom:30rpx;
		border-radius:18rpx;
	}
	.list-wrap{
		min-height:360rpx;
		
		padding:30rpx 20rpx 1rpx 20rpx;
		border-radius:30rpx;
		
	}
	.next{
		
		background:#f9436b;
		color:#fff;
		width:668rpx;
		margin:0 auto;
		display:flex;
		justify-content: center;
		align-items: center;
		height:80rpx;
		margin-top:60rpx;
		border-radius:12rpx;
	}
	.title-bold{
		text-align:center;
		padding-top:18rpx;
		color:#5e5e5e;
	}
	
	.ipt-wrap .label{
		width:180rpx;
	}
	.ipt-wrap .right{
		flex:1;
	}
	.right input{
		height:100%;
	}
	.img-wrap{
		padding-top:20rpx;
		width:604rpx;
		margin:0 auto;
		display:flex;
		text-align:center;
		margin-bottom:18rpx;
	}
	.note-wrap{
		width:604rpx;
		margin:0 auto;
	}
	.img-item{
		
		flex:1;
	}
	.img-item .img{
		height:180rpx;
		
		text-align:center;
		width:96%;
	}
	.ipt-wrap{
		
		display:flex;
		align-items: center;
		width:664rpx;
		margin:0 auto;
		
		padding:30rpx 0;
		border-bottom:1rpx solid #e8e8e8
	}
	
	.bold-border{
		border-bottom:10rpx solid #e8e8e8
	}

	/* .name-wrap{
		border-bottom:1rpx solid #e8e8e8
	} */
	.wrap{
		// background:url(/static/fuyang_bg.jpg) no-repeat center 0;
		// background-size:100% auto;
		// padding-top:950rpx;
	}
	.tips{
		color:#333;
		line-height:70rpx;
		background:#eeeeee;
		padding:34rpx 44rpx 34rpx 30rpx;
	}
	
	
	
	.navbar{
		box-sizing: border-box;
		display: flex;
		height: 00rpx;
		/* width:700rpx; */
		margin:0 auto;
		left:0;
		right:0;
		
		padding:0rpx 20rpx;
		top:0;
		background: #f7f7f7;
		
		position:absolute;
		z-index: 10;
		
		.nav-item{
			border-radius: 14rpx;
			
			flex: 1;
			
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			
			font-size: 15px;
			color: $font-color-dark;
			position: relative;
			
			&.current{
				
				background:#fff;
				color: $base-color;
			}
		}
	}
	
	
	.data-wrap .dot{
		background:#fff;
		height:22rpx;
		border-radius:50%;
		margin-right:28rpx;
		width:22rpx;
	}
	.data-wrap .left{
		background-size:80rpx 80rpx;
		min-height:80rpx;
		display:flex;
		padding-left:0rpx;
		align-items: center;
	}
	.data-wrap .right{
		color:#e95758
	}
	
	.data-wrap{
		width:656rpx;
		margin:0 auto;
		margin-top:20rpx;
		height:136rpx;
		display:flex;
		align-items: center;
		justify-content: space-between;
		background:#fff;
		border-radius:20rpx;
		color:#000;
		padding: 0 10rpx 0 10rpx; 
	}
	
	.signcom{
		background:url(/static/yiwancheng.png) no-repeat right top #fff!important;
		background-size:100rpx auto!important;
	}
	page{
		background:#f6f6f6;
		font-size:36rpx;
	}
</style>
